package com.nf.action;

import com.nf.entity.Account;
import com.nf.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;


@SessionAttributes("account")
@Controller
public class Login_Exit_action {
    @Autowired
    private AccountService accountService;

    //登录
    @RequestMapping("/Login")
    public String Login(){
        return "login";
    }
    //注册
    @RequestMapping("addAccount")
     public String addAccount(){
        return "addaccount";
     }
    //注册业务
    @RequestMapping("addAccountgo")
    public String addAccountgo(Account account,String CarNo,String passWord,String passWordOk){
        account.setCardNo(CarNo);
        account.setValidDate(new java.sql.Date(System.currentTimeMillis()));
        System.out.println("确认密码"+passWordOk);
        if(!passWord.equals(passWordOk)){
            return "redirect:addAccount";
        }
        accountService.addAccount(account);
        return "login";
    }
    //登录验证
    @RequestMapping("/logingo")
    public String logingo(String userName, String passWord,Model modle){
        Account account = accountService.login(userName,passWord);
        if(account==null){
            modle.addAttribute("message","LOGIN_ERROR");
            return "redirect:Login";
        }
        modle.addAttribute("account",account);
        return "index";
    }
    //退出
    @RequestMapping("/exit")
    public String exit(@ModelAttribute("account")Account account, SessionStatus sessionStatus){
        sessionStatus.setComplete();
        return "redirect:Login";

    }

}
